package org.aeon.colorfulplanebattle.view.panel;

import org.aeon.colorfulplanebattle.constant.ColorE;
import org.aeon.colorfulplanebattle.flying.Utils;
import org.aeon.colorfulplanebattle.view.GameState;
import org.aeon.colorfulplanebattle.view.components.ColorBlock;

import javax.swing.*;
import java.awt.*;

import static org.aeon.colorfulplanebattle.constant.GameBasisConstant.COLOR_BLOCK_QUANTITY;

/**
 * @author: MissingAeon
 * @date: 2024/1/8 19:26
 * @description:
 */
public class BottomPanel extends JPanel {
    private final GameState gameState;
    private final ColorBlock[] colorBlock = new ColorBlock[COLOR_BLOCK_QUANTITY];

    public BottomPanel(GameState gameState) {
        this.gameState = gameState;
        this.setLayout(new GridLayout(1, COLOR_BLOCK_QUANTITY));
        initComponents();
        gameState.put("BottomPanelReset", (Runnable) this::reset);
    }


    /**
     * 初始化组件
     */
    private void initComponents() {
        ColorE[] blockEs = ColorE.values();
        Utils.shuffleArray(blockEs);
        for (int i = 0; i < colorBlock.length; i++) {
            colorBlock[i] = new ColorBlock(blockEs[i].getColor());
        }
        gameState.put("blockEs", blockEs);
        filling();
    }

    /**
     * 填充
     */
    private void filling() {
        // Utils.shuffleArray(colorBlock);
        for (ColorBlock block : colorBlock) {
            this.add(block);
        }
    }

    private void reset() {
    }
}
